package com.example.shopping_li.utils;


import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.util.Map;

//联网的Fragment的基类
public class BaseActivity extends AppCompatActivity implements Callback.CommonCallback<String> {

  public void connectNet(String url){
    Log.i("lsh", "connectNet: url=="+url);
    //请求参数
    RequestParams params = new RequestParams(url);
    x.http().get(params,this);
  }
  public void postNetwork(String url, Map<String,String> map){
    RequestParams params=new RequestParams(url);
    params.setAsJsonContent(true);
    params.setBodyContentType("application/json;charset=UTF-8");
    for (Map.Entry<String,String>entry:map.entrySet()){
      String key=entry.getKey();
      String value=entry.getValue();
      params.addParameter(key,value);
    }
    x.http().post(params,this);

  }
  @Override
  public void onSuccess(String result) {
    Log.i("lsh", "onSuccess:res== "+result);
  }
  @Override
  public void onError(Throwable ex, boolean isOnCallback) {
    Log.i("lsh12", "onError: eeee==="+ex.getMessage());
  }

  @Override
  public void onCancelled(CancelledException cex) {

  }

  @Override
  public void onFinished() {

  }
}